package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysAppBookinfo;
import com.ruoyi.system.service.ISysAppBookinfoService;

/**
 * 书籍信息Controller
 * 
 * @author ruoyi
 * @date 2020-09-06
 */
@Controller
@RequestMapping("/system/bookinfo")
public class SysAppBookinfoController extends BaseController {
	private String prefix = "system/bookinfo";

	@Autowired
	private ISysAppBookinfoService sysAppBookinfoService;

	@RequiresPermissions("system:bookinfo:view")
	@GetMapping()
	public String bookinfo() {
		return prefix + "/bookinfo";
	}

	/**
	 * 查询书籍信息列表
	 */
	@RequiresPermissions("system:bookinfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysAppBookinfo sysAppBookinfo) {
		startPage();
		List<SysAppBookinfo> list = sysAppBookinfoService.selectSysAppBookinfoList(sysAppBookinfo);
		return getDataTable(list);
	}

	/**
	 * 导出书籍信息列表
	 */
	@RequiresPermissions("system:bookinfo:export")
	@Log(title = "书籍信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(SysAppBookinfo sysAppBookinfo) {
		List<SysAppBookinfo> list = sysAppBookinfoService.selectSysAppBookinfoList(sysAppBookinfo);
		ExcelUtil<SysAppBookinfo> util = new ExcelUtil<SysAppBookinfo>(SysAppBookinfo.class);
		return util.exportExcel(list, "bookinfo");
	}

	/**
	 * 新增书籍信息
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存书籍信息
	 */
	@RequiresPermissions("system:bookinfo:add")
	@Log(title = "书籍信息", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SysAppBookinfo sysAppBookinfo) {
		return toAjax(sysAppBookinfoService.insertSysAppBookinfo(sysAppBookinfo));
	}

	/**
	 * 修改书籍信息
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppBookinfo sysAppBookinfo = sysAppBookinfoService.selectSysAppBookinfoById(id);
		mmap.put("sysAppBookinfo", sysAppBookinfo);
		return prefix + "/edit";
	}

	/**
	 * 修改保存书籍信息
	 */
	@RequiresPermissions("system:bookinfo:edit")
	@Log(title = "书籍信息", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SysAppBookinfo sysAppBookinfo) {
		return toAjax(sysAppBookinfoService.updateSysAppBookinfo(sysAppBookinfo));
	}

	/**
	 * 删除书籍信息
	 */
	@RequiresPermissions("system:bookinfo:remove")
	@Log(title = "书籍信息", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sysAppBookinfoService.deleteSysAppBookinfoByIds(ids));
	}
}
